package com.dpiinc.TechPage.room.dao

import androidx.paging.DataSource
import androidx.room.*
import com.dpiinc.TechPage.room.bean.NoteEntity

@Dao
interface NoteDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(notes: List<NoteEntity>)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(note: NoteEntity)

    @Update
    fun update(note: NoteEntity)

    @Delete
    fun delete(note: NoteEntity)

    @Query("DELETE FROM notes WHERE noteId = :id")
    fun delete(id: String)

    @Query("DELETE FROM notes")
    fun deleteAll()

    @Query("SELECT * FROM notes ORDER BY modifyTime desc")
    fun getNotesAsDataSource(): DataSource.Factory<Int, NoteEntity>

    @Query("SELECT * FROM notes ORDER BY modifyTime desc")
    fun getNotes(): List<NoteEntity>

    @Query("SELECT * FROM notes ORDER BY modifyTime desc limit 1")
    fun getLastNote(): List<NoteEntity>

    @Query("SELECT * FROM notes WHERE noteId = :id")
    fun getNote(id: String): List<NoteEntity>
}